<?php

use think\migration\Migrator;
use think\migration\db\Column;

class VoteInfoTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $this->table('vote_info', ['comment'=>'投票名称'])
            ->addColumn(Column::string('title')->setComment("活动主题"))
            ->addColumn(Column::integer('start_time')->setComment("活动开始时间"))
            ->addColumn(Column::integer('end_time')->setComment("活动结束时间"))
            ->addColumn(Column::enum('vote_type', ['单选投票', '必选投票', '多选投票'])->setDefault('必选投票')->setComment("投票类型"))
            ->addColumn(Column::integer('vote_min')->setDefault(1)->setComment("投票限制"))
            ->addColumn(Column::integer('vote_max')->setDefault(1)->setComment("投票限制"))
            ->addColumn(Column::enum('period', ['固定次数', '周期次数'])->setDefault('固定次数')->setComment("周期"))
            ->addColumn(Column::integer('period_value')->setDefault(1)->setComment("周期次数"))
            ->addColumn(Column::enum('sort_way', ['编号正序', '票数倒序', '时间排序'])->setDefault('编号正序')->setComment("排序方式"))
            ->addColumn(Column::integer('init_vote')->setDefault(0)->setComment("初始票数"))
            ->addColumn(Column::integer('init_browse')->setDefault(0)->setComment("初始访问量"))
            ->addColumn(Column::string('images')->setComment("图片")->setNullable())
            ->addColumn(Column::longText('content')->setComment("内容")->setNullable())
            ->addColumn(Column::enum('status', ['未开始', '进行中', '已结束'])->setDefault('未开始')->setComment("状态"))
            ->addColumn(Column::integer('create_time')->setComment('创建时间')->setNullable())
            ->addColumn(Column::integer('update_time')->setComment('修改时间')->setNullable())
            ->addColumn(Column::integer('delete_time')->setComment('删除时间')->setNullable())
            ->create();
    }
}
